package example.hello_security;

import example.hello_security.user.domain.Operator;
import example.hello_security.user.repo.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
@EnableJpaRepositories
public class HelloSecurityApplication {

	public static void main(String[] args) {
		SpringApplication.run(HelloSecurityApplication.class, args);
	}

	@Bean
	public CommandLineRunner demo(UserRepository repository, PasswordEncoder passwordEncoder) {
		return (args) -> {
			// save a few customers
			repository.save(new Operator("admin", 15,passwordEncoder.encode("xiao"),"ADMIN"));
			repository.save(new Operator("dep", 18,passwordEncoder.encode("xiao"),"DEP_ADMIN"));
		};
	}

}
